import win32gui
import win32con
import win32api
import win32clipboard as w
from pywinauto import Application#pip install pywinauto
import time


def get_son_windows(parent):
      hWnd_child_list = []
      win32gui.EnumChildWindows(parent, lambda hWnd, param: param.append(hWnd), hWnd_child_list)
    #   print(hWnd_child_list)
      return hWnd_child_list

# windows_name = r"斯维尔清单计价 TH-BQ2016 学习版"
# print(windows_name)
# hwnd = win32gui.FindWindow(None, windows_name)
# if hwnd:
#     # win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
#     print(f"窗口句柄为：{hwnd}")
# else:
#     print("未找到指定窗口")


def get_menu_item_txt(menu,idx):
    import win32gui_struct
    mii, extra = win32gui_struct.EmptyMENUITEMINFO() #新建一个win32gui的空的结构体mii
    win32gui.GetMenuItemInfo(menu, idx, True, mii) #将子菜单内容获取到mii
    ftype, fstate, wid, hsubmenu, hbmpchecked, hbmpunchecked,\
    dwitemdata, text, hbmpitem = win32gui_struct.UnpackMENUITEMINFO(mii) #解包mii
    return text


hwnd = 198084

list = get_son_windows(hwnd)
project_compose = 0
electri_book = 0
construct_project= 0
for handle in list:
    name = win32gui.GetWindowText(handle)
    if name == '项目组成':
         project_compose = handle
    elif name == '电子标书' :
         electri_book = handle
    elif name.startswith("建设项目") :
         construct_project = handle
    print(name)

print(project_compose)
print(electri_book)
print(construct_project)
print("-----")


app = Application(backend='uia').connect(handle = hwnd)
print(win32gui.GetWindowText(hwnd))
win = app.window(title_re= win32gui.GetWindowText(hwnd))
proc = win.child_window(auto_id="198700", control_type="Tab")
print(proc.print_ctrl_ids())
# elec = win.child_window(title="电子标书", control_type="TabItem")
# win.
# print(win.print_ctrl_ids())




